package net.csdn.business.discuss.api.controller;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import net.csdn.business.discuss.api.facade.DiscussCommentWrapperFacade;
import net.csdn.business.discuss.api.model.dto.*;
import net.csdn.business.discuss.api.model.query.DiscussCommentQuery;
import net.csdn.business.discuss.api.model.vo.DiscussCommentVO;
import net.csdn.business.discuss.api.service.IDiscussCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName DiscussCommentController
 * @Description 讨论评论Controller
 * @Author zhangyl
 * @Date 2023/7/18 11:30
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/discuss/comment")
public class DiscussCommentController
{
    @Autowired
    private IDiscussCommentService discussCommentService;

    @Autowired
    private DiscussCommentWrapperFacade discussCommentWrapperFacade;

    /**
     * 分页查询讨论评论列表
     */
    @PostMapping("/page")
    public Page<DiscussCommentVO> findPageList(@RequestBody  DiscussCommentQuery query) throws Exception
    {
        return discussCommentService.findPageList(query);
    }

    /**
     * 分页查询讨论评论的回复列表
     */
    @PostMapping("/reply/page")
    public Page<DiscussCommentVO> findReplyPageList(@RequestBody  DiscussCommentQuery query)  throws Exception
    {
        return discussCommentService.findReplyPageList(query);
    }

    /**
     * 根据id获取讨论评论详细信息
     */
    @GetMapping(value = "/{id}")
    public DiscussCommentVO getInfo(@PathVariable("id") String id)
    {
        return discussCommentService.selectDiscussCommentById(id);
    }

    /**
     * 新增讨论评论
     */
    @PostMapping
    public String add(@RequestBody @Validated NewDiscussCommentDTO discussComment)
    {
        return discussCommentWrapperFacade.add(discussComment);
    }

    /**
     * 新增讨论评论的回复
     */
    @PostMapping("/reply")
    public Integer addReply(@RequestBody @Validated NewDiscussReplyDTO params)
    {
        return discussCommentService.insertDiscussReply(params);
    }

    /**
     * 修改讨论评论
     */
    @PutMapping
    public Integer edit(@RequestBody UpdateDiscussCommentDTO discussComment)
    {
        return discussCommentWrapperFacade.edit(discussComment);
    }

    /**
     * 修改讨论评论的回复
     */
    @PutMapping("/reply")
    public Integer editReply(@RequestBody UpdateDiscussReplyDTO params)
    {
        return discussCommentService.updateDiscussReply(params);
    }

    /**
     * 删除讨论评论
     */
	@DeleteMapping
    public Integer remove(@RequestBody @Validated DeleteResourceDTO params)
    {
        return discussCommentWrapperFacade.remove(params);
    }

    /**
     * 删除讨论评论
     */
    @DeleteMapping("/reply")
    public Integer removeReply(@RequestBody @Validated DeleteResourceDTO params)
    {
        return discussCommentService.deleteDiscussReplyById(params);
    }

    /**
     * 采纳为答案
     */
    @PostMapping("/remark")
    public Integer remarkAnswer(@RequestBody @Validated RemarkAnswerDTO params)
    {
        return discussCommentService.remarkAnswer(params);
    }

    /**
     * 取消采纳为答案
     */
    @PostMapping("/unremark")
    public Integer unRemarkAnswer(@RequestBody @Validated RemarkAnswerDTO params)
    {
        return discussCommentService.unRemarkAnswer(params);
    }


    /**
     * 更新审核状态
     */
    @PostMapping("/updateAuditStatus")
    public Integer updateAuditStatus(@RequestBody @Validated UpdateAuditStatusDTO params){
        log.info("discuss comment update audit status params:{}", JSON.toJSONString(params));
        return discussCommentService.updateAuditStatus(params);
    }
}
